package com.video.moderation.repository;

import com.video.moderation.entity.VideoInfo;
import com.video.moderation.entity.vo.VideoDetailVo;
import com.video.moderation.entity.vo.VideoListVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface VideoInfoPageRepository extends PagingAndSortingRepository<VideoInfo, String> {

    @Query("SELECT new com.video.moderation.entity.vo.VideoListVo(v.videoId, u.nickname, v.videoTitle, v.status, v.publishTime) " +
            "FROM VideoInfo v INNER JOIN SysUser u ON u.userId = v.userId " +
            "ORDER BY v.videoId")
    Page<VideoListVo> queryVideoList(Pageable pageable);

    @Query("SELECT new com.video.moderation.entity.vo.VideoDetailVo" +
            "(v.videoId, v.userId, vt.typeName, u.nickname, v.videoTitle, v.thumbnail, v.url, v.description, v.publishTime)" +
            "FROM VideoInfo v INNER JOIN SysUser u ON u.userId = v.userId " +
            "INNER JOIN VideoType vt ON vt.typeId = v.typeId WHERE v.videoId = :videoId")
    VideoDetailVo queryVideoDetailById(@Param("videoId") String videoId);

}
